/*
 * Copyright 2008 [rapid-framework], Inc. All rights reserved.
 * Website: http://www.rapid-framework.org.cn
 */

    define("pages/jls_gwjjb/main", [
    	  "../../plugins/easyui/jquery-easyui-1.5.1/jquery.easyui.min",
         "../../plugins/easyui/jquery-easyui-1.5.1/easyloader",
           "../../plugins/artTemplate/artTemplate",
           "../../common/tools",
         "../../common/componts",
//         "../../common/kss",
//          "../../pages/jls_gwjjb/form",
         "../../pages/jls_gwjjb/GwjjbShowHide.html.js",
        ],
        function(require) {
        var comonts=require("../../common/componts");
        var kss=require("../../common/kss");
        var GwjjbForm=require("../../pages/jls_gwjjb/form");
        var tmp=require("../../pages/jls_gwjjb/GwjjbShowHide.html");
        var gwjjbId="gwjjbId";
        var selectid;
        var top="30px";
        var gwjjb='gwjjb';


            var initHtml = function(){
                var user_permission = 2 ; 	//设置获取到的用户权限
                var rsdj_permission = 2 ;	//设置出所管理需要的权限
                var container = document.getElementById("main");
                var graph = new mxGraph(container);
                var parent = graph.getDefaultParent();

                graph.setHtmlLabels(true);

                graph.setEnabled(false);

                var style = {};

                style = graph.getStylesheet().getDefaultEdgeStyle();//圆角连线
                style[mxConstants.STYLE_ROUNDED] = true;//圆角连线
                style = mxUtils.clone(style);
                style[mxConstants.STYLE_SHAPE] = mxConstants.SHAPE_LABEL;  // 不设置这个属性 背景图片不出来

                style[mxConstants.STYLE_STROKECOLOR] = '#f5f5f5';

                style[mxConstants.STYLE_FILLCOLOR] = '#f5f5f5';

                style[mxConstants.STYLE_FONTCOLOR] = 'black';

                style[mxConstants.STYLE_ALIGN] = mxConstants.ALIGN_CENTER;

                style[mxConstants.STYLE_VERTICAL_ALIGN] = mxConstants.ALIGN_BOTTOM;

                style[mxConstants.STYLE_FONTSIZE] = 13;

                style[mxConstants.STYLE_IMAGE_ALIGN] = 0;

                style[mxConstants.STYLE_IMAGE_VERTICAL_ALIGN] = 0;

                style[mxConstants.STYLE_IMAGE] = '../../img/lcttx.png';

                style[mxConstants.STYLE_IMAGE_WIDTH] = 80;

                style[mxConstants.STYLE_IMAGE_HEIGHT] = 80;

                style[mxConstants.STYLE_SPACING_TOP] = 30;

                style[mxConstants.STYLE_SPACING] = 0.5;

                graph.getStylesheet().putCellStyle("style1", style);

                var style2 = {};

                style2 = graph.getStylesheet().getDefaultEdgeStyle();//圆角连线
                style2[mxConstants.STYLE_ROUNDED] = true;//圆角连线
                style2 = mxUtils.clone(style);
                style2[mxConstants.STYLE_SHAPE] = mxConstants.SHAPE_LABEL;  // 不设置这个属性 背景图片不出来

                style2[mxConstants.STYLE_STROKECOLOR] = '#f5f5f5';

                style2[mxConstants.STYLE_FILLCOLOR] = '#f5f5f5';

                style2[mxConstants.STYLE_FONTCOLOR] = 'black';

                style2[mxConstants.STYLE_ALIGN] = mxConstants.ALIGN_CENTER;

                style2[mxConstants.STYLE_VERTICAL_ALIGN] = mxConstants.ALIGN_BOTTOM;

                style2[mxConstants.STYLE_FONTSIZE] = 13;

                style2[mxConstants.STYLE_IMAGE_ALIGN] = 0;

                style2[mxConstants.STYLE_IMAGE_VERTICAL_ALIGN] = 0;

                style2[mxConstants.STYLE_IMAGE] = '../../img/zh.png';

                style2[mxConstants.STYLE_IMAGE_WIDTH] = 80;

                style2[mxConstants.STYLE_IMAGE_HEIGHT] = 80;

                style2[mxConstants.STYLE_SPACING_TOP] = 30;

                style2[mxConstants.STYLE_SPACING] = 0.5;

                graph.getStylesheet().putCellStyle("style2", style2);




                //获取流程节点的待办数量
                var jbdjCount=0;
                var jbqrCount=0;



                // 画人物
                var v1 = graph.insertVertex(parent, 'jbdj', '交班登记<font color="red"></font>', 200, 220, 100, 105, "style1");
                var v2 = graph.insertVertex(parent, 'jbldqr', '交班领导确认<font color="red"></font>', 400, 220, 100, 105, "style2");
                var v3 = graph.insertVertex(parent, 'jbqr', '接班确认<font color="red"></font>', 600, 220, 100, 105,"style2");
                var v4= graph.insertVertex(parent, 'jeldqr', '接班领导确认<font color="red"></font>', 800, 220, 100, 105,"style2");

                // 连线
                graph.insertEdge(parent, null, '',v1, v2 , "edgeStyle=elbowEdgeStyle;");
                graph.insertEdge(parent, null, '',v2, v3 , "edgeStyle=elbowEdgeStyle;");
                graph.insertEdge(parent, null, '',v3, v4 , "edgeStyle=elbowEdgeStyle;");





                //添加事件
                graph.addListener(mxEvent.CLICK, function(sender, evt) {
                    var cell11 = evt.getProperty('cell');
                    //graph.setCellStyles(fillColor,black);
                    if(cell11==null){
                        $("#pictureId").css({"display":"none"});
                        return ;
                    }else if(cell11.id=='jbdj'){
                        window.location.href='/jls_gwjjb/jbdjForm.html';
                    }else if (cell11.id=='ksrs'){
                        window.location.href='';
                    }else if(cell11.id=='jydj'){

                    }
                });
                //鼠标悬浮效果
                var track = new mxCellTracker(graph);
                var self = this;
                track.mouseMove = function(sender, me) {
                    var cell1 = this.getCell(me);
                    if(cell1==null){
                        $("#pictureId").css({"display":"none"});
                        return ;
                    }else{
                        if(cell1.id=="tscldj"){
                            $("#pictureId").css({"display":"block","left":"250px","top":"170px"});
                            $("#pictureId").html("投诉处理登记登记！");
                        }else if (cell1.id=="ldsp"){
                            $("#pictureId").css({"display":"block","left":"550px","top":"170px"});
                            $("#pictureId").html("领导审批！");
                        }else if (cell1.id=="cldjcljg"){
                            $("#pictureId").css({"display":"block","left":"850px","top":"170px"});
                            $("#pictureId").html("登记处理结果！");
                        }
                    }
                };
                //
                function bodyScale(){
                    var main = document.getElementById("main"); //获取id="main"
                    var devicewidth=document.documentElement.clientWidth;
                    var scale=devicewidth/1275;//除去当前流量器分辨率1275
                    main.style.zoom=scale;//zoom是设置或检索对象的缩放比例.
                }
                window.onload=window.onresize=function(){
                    bodyScale();
                }
                //自适应任何设备屏幕
                function bodyScale(){
                    var main = document.getElementById("main"); //获取id="main"
                    var devicewidth=document.documentElement.clientWidth;
                    var scale=devicewidth/1275;//除去当前流量器分辨率1275
                    main.style.zoom=scale;//zoom是设置或检索对象的缩放比例.
                }
                window.onload=window.onresize=function(){
                    bodyScale();
                }
            }






        var initTable=function(){
            comonts.initTable(gwjjbId,{
                title: '',
                url:"/jls_gwjjb/gwjjbList",
                tools:'#tool',
                firstLoad:true,
                pageSize: 20,
                columns:[
                    {field: 'oid',title: '',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="gwjjbIdRadio" id="gwjjbIdRadio"' + rowIndex + 'value="' + rowData.oid + '" />';}},
                    {
                        field : 'id',
                        width : 150,
                        title:'序号',
                        sortable:'true',
                        formatter: function(value,row,index){
                            return '<span title='+value+'>'+(row.id == null ? "" : row.id)+'</span>'
                        }},
                    {
                        field : 'rybh',
                        width : 150,
                        title:'交班岗位',
                        sortable:'true',
                        formatter: function(value,row,index){
                            return '<span title='+value+'>'+(row.rybh == null ? "" : row.rybh)+'</span>'
                        }},
                    {
                        field : 'xm',
                        width : 150,
                        title:'交班人员',
                        sortable:'true',
                        formatter: function(value,row,index){
                            return '<span title='+value+'>'+(row.xm == null ? "" : row.xm)+'</span>'
                        }},
                    {
                        field : 'jsh',
                        width : 150,
                        title:'交班时间',
                        sortable:'true',
                        formatter: function(value,row,index){
                            return '<span title='+value+'>'+(row.jsh == null ? "" : row.jsh)+'</span>'
                        }},
                    {
                        field : 'bahj',
                        width : 150,
                        title:'接班人员',
                        sortable:'true',
                        formatter: function(value,row,index){
                            return '<span title='+value+'>'+(row.bahj == null ? "" : row.bahj)+'</span>'
                        }},
                    {
                        field : 'rssj',
                        width : 150,
                        title:'接班时间',
                        sortable:'true',
                        formatter: function(value,row,index){
                            return '<span title='+value+'>'+(row.rssj == null ? "" : row.rssj)+'</span>'
                        }},
                    {
                        field : 'gyqx',
                        width : 150,
                        title:'详细信息',
                        sortable:'true',
                        formatter: function(value,row,index){
                            return '<span title='+value+'>'+(row.gyqx == null ? "" : row.gyqx)+'</span>'
                        }},
                   
                    ],
                detailFormatter:function(index,rowData){
                    return '<table style="height:40px;width:100%"><tr><td><strong></strong></td></tr></table>'
                },
                onClickRow:function(rowIndex, rowData){
                    if (selectid != rowData.id) {
                        $("input[name='gwjjbIdRadio']")[rowIndex].checked = true;
                        $('#' + gwjjbId).datagrid("selectRow", rowIndex);
                        selectid = rowData.id;
                    } else if (selectid == rowData.id) {
                        $('#' + gwjjbId).datagrid("unselectRow", rowIndex);
                        $("input[name='gwjjbIdRadio']")[rowIndex].checked = false;
                        selectid = "";
                    }
                },
            });
            $('#gwjjbId').datagrid('resize', {
                height: ($(window).height()-150 )
            });
        }
        var findGwjjb=function(){
            var opts = $('#'+gwjjbId).datagrid("options");
            opts.url = "/jls_jbxx/jbxxList";
            $('#'+gwjjbId).datagrid('clearSelections');
            $('#'+gwjjbId).datagrid('load',{
            });
        }
        var addValue=function (Gwjjb){
            var row = $('#gwjjbId').datagrid('getSelected');
            var ss=JSON.stringify(row);
            var ssScbh=JSON.stringify(Gwjjb);
            console.log("d=="+ssScbh+"=;;");
            if(Gwjjb){
                $('#gwjjb_rybhs').textbox('setValue',Gwjjb.id);
                $('#gwjjb_xm').textbox('setValue',Gwjjb.xm);
            }
        }
        var bindAction=function(){
            //查询
            $("#gwjjb_search").on("click",function(){
                findGwjjb();
            });
            //新增
            $("#gwjjb_add").on("click",function(){
                var gwjjb=$("#"+gwjjbId).datagrid('getSelected');
                if(Gwjjb){
                	GwjjbForm.show(findGwjjb,Gwjjb);
                    addValue(Gwjjb);
                }else{
                    $.messager.alert("提示","请选择要办理的人员!","info");
                }
            });
            $("#gwjjb_add2").on("click",function(){
                var Gwjjb=$("#"+gwjjbId).datagrid('getSelected');
                if(Gwjjb){
                	GwjjbForm.show(findgwjjb,Gwjjb);
                }else{
                    $.messager.alert("提示","请选择要办理的人员!","info");
                }
            });
            //修改
            $("#gwjjb_update").on("click",function(){
                var Gwjjb=$("#"+gwjjbId).datagrid('getSelected');
                if(Gwjjb){
                	GwjjbForm.show(findGwjjb,Gwjjb);
                }else{
                    $.messager.alert("提示","请选择要修改的记录!","info");
                }
            });
            //删除
            $("#gwjjb_remove").on("click",function(){
                //把你选中的 数据查询出来。
                var selectRows = $('#gwjjbId').datagrid("getSelections");
                if(selectRows==null||selectRows==undefined){

                    return  $.messager.alert("提示消息", "请选中要删的数据!");
                }else{
                    $.messager.confirm("操作提示", "您确定要删除该条记录吗？", function (data) {

                        if(data) {
                            submitLoad();
                            $.ajax({
                                type : "POST",  //提交方式
                                url : "/jls_gwjjb/gwjjbDelete",//路径
                                data : {id:selectRows[0].id},//数据，这里使用的是Json格式进行传输
                                success : function(result) {
                                    if (result.success) {
                                        $.messager.alert("确定","删除成功","info");
                                        findGwjjb();
                                    }else{
                                        removeLoad();
                                        $.messager.alert("确定","删除失败","info");
                                    }
                                },
                                complete:function(){
                                    removeLoad();
                                },
                            });
                        }else {
                            return false;
                        }

                    });

                }
            });
            // comonts.ShowHide(gwjjb,tmp);
        }






        var initView=function(){

            initHtml();
            initTable();
            bindAction();
        }
        initView();

    });